<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<link rel="icon" type="image/png" href="img/favicon.ico">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>指纹单元</title>
		<link rel="stylesheet" href="css/style.min.css" />
	</head>

	<body>

		<header id="header" class="header">
			<div class="logo">
				<img src="img/logo.png" alt="logo" style="height: 62px;">
			</div>
			<div class="nav">
				<ul class="header-list">
					<li>
						<a class="active" href="index.html">指纹库</a>
					</li>
					<li>
						<a href="config.html">系统设置</a>
					</li>
					<li>
						<a href="collect.html">指纹录入</a>
					</li>
				</ul>
			</div>
		</header>
		<div class="content">
			<fieldset>
				<legend>员工信息</legend>
				<table cellpadding="0" cellspacing="0">
					<tbody>
						<tr>
							<td width="35%" align="right">工号：</td>
							<td style="padding: 0;">
								<input id="code" name="code" class="inputxt" type="text" value="" maxlength="10"/>
							</td>
						</tr>
						<tr>
							<td width="35%" align="right">姓名：</td>
							<td style="padding: 0;">
								<input id="name" name="name" class="inputxt" type="text" value=""  maxlength="5"/>
							</td>
						</tr>
						<tr>
							<td width="35%" align="right">性别：</td>
							<td style="padding: 0;">
								<select  class="inputxt" id="sex" name="sex">
									<option value="1">男</option>
									<option value="0">女</option>
								</select>
							</td>
						</tr>
					</tbody>
				</table>
			</fieldset>
			<button type="button" class="btn btn-success btn-block" onclick="javascript:saveEmp();">保存</button>
		</div>
		<div id="content">
		</div>
	</body>
	<script type="text/javascript" src="js/app.min.js"></script>
	<script type="application/javascript">	
		function saveEmp() {			
			var code = document.getElementById("code").value;
			var name = document.getElementById("name").value;
			var sex = document.getElementById("sex").value;
			ajax({
				url: 'savemp.cgi',
				data: {
					code: code,
					name: name,
					sex: sex
				},
				method: 'POST',
				success: function(rsp) {
					var obj = JSON.parse(rsp);
					console.log(rsp);
					if(obj.res == '0') {
						window.location.href = 'index.html';
					}else{
						var empbody = document.getElementById('content');
						var html = "";
						html += "<div class='alert alert-danger'><strong>消息提示：</strong> 此工号已录入，请确定！</div>";
						empbody.innerHTML = html;
						setTimeout(function(){empbody = document.getElementById('content');empbody.innerHTML = " ";},1000);
					}
				},
				error: function(rsp) {
					console.log(rsp);
				}
			});
		}
	</script>

</html>